/*
	***************************
	* PCMod 2 SS Device Element *
	***************************
	
	 Element: Button

*/

local PANEL = {}

function PANEL:Initialize()
	self.Locked = false
	self.Active = false
	self.HasIcon = false
	self.Icon = ""
	self.Text = "Button"
end

function PANEL:Paint()
	local c_bor = self:GetCol( "Border" )
	local c_btbg = self:GetCol( "ButtonBG" )
	local c_bt_txt = self:GetCol( "Button_Text" )
	if (self.Locked) then
		c_bor = self:GetCol( "Border_Locked" )
		c_bt_txt = self:GetCol( "Button_Text_Locked" )
	end
	if (self.Active) then
		c_btbg = self:GetCol( "ButtonBG_Active" )
	end
	if (!self:CallThemeHook( "button", self:GetStruct() )) then
		surface.SetDrawColor( c_btbg.r, c_btbg.g, c_btbg.b, 255 )
		surface.DrawRect( self.X, self.Y, self.W , self.H )
		surface.SetDrawColor( c_btbg.r - 50, c_btbg.g - 50, c_btbg.b - 50, 255 )
		surface.DrawRect( self.X + 4, self.Y + 4, self.W - 4 , self.H - 4 )
		surface.SetDrawColor( c_btbg.r - 25, c_btbg.g - 25, c_btbg.b - 25, 255 )
		surface.DrawRect( self.X + 4, self.Y + 4, self.W - 8 , self.H - 8 )
	end
	draw.SimpleText( self.Text, "pcmod_3d2d", self.X + (self.W / 2) , self.Y + (self.H / 2), c_bt_txt, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)
	if (self.HasIcon) then
		local ico = self.Icon
		local fn = "gui/icons/ico_" .. ico
		local sid = PCMod.Res.Mats[ fn ]
		surface.SetTexture( sid )
		surface.SetDrawColor( 255, 255, 255, 255 )
		surface.DrawTexturedRect( self.X + 1, self.Y, self.H - 3, self.H - 3) -- Yes, self.H is repeated on purpose
	end
end

function PANEL:SetText( txt )
	self.Text = txt
end

function PANEL:SetIcon( ico )
	self.Icon = ico
	if ((ico) && (ico != "")) then self.HasIcon = true end
end

PCMod.SSEL.Register( "Button", PANEL )